package edu.dayu.sort;

import java.util.Arrays;

/**
 * @author: dayu
 * @date: 2023/6/21 17:42
 * 希尔排序
 * 希尔是基于插入排序的
 */
public class ShellSort {
    public static void main(String[] args) {
        int[] arr = {6,4,5,7,2,8,3,0,9,1};
        int gap = arr.length/2;
        while (gap>0){
            for (int i = gap; i < arr.length; i++) {
                int j;
                int temp = arr[i];
                for (j = i-gap;j >=0;j-=gap){
                    if (temp>arr[j]){
                        break;
                    }else {
                        arr[j+gap] = arr[j];
                    }
                }
                arr[j+gap] = temp;
            }
            gap/=2;
            System.out.println(Arrays.toString(arr));
        }
    }
}
